package com.ruoyi.web.app.chat;

import com.ruoyi.common.base.chat.domain.Chat;
import com.ruoyi.common.base.chat.dto.ChatEditDTO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.service.IChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 会话Controller
 *
 * @author gdk
 * @date 2023-05-15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/chat")
public class ChatAppController extends BaseController {
    private final IChatService chatService;

    /**
     * 会话列表
     *
     * @param condition 条件
     * @return {@link TableDataInfo}
     * @author gdk
     * @since 2023/5/16 16:42
     */
    @GetMapping("/list")
    public TableDataInfo list(Chat condition) {
        startPage();
        return chatService.appList(condition);
    }

    /**
     * 修改会话
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/16 17:27
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ChatEditDTO dto) {
        chatService.edit(dto);
        return success();
    }

    /**
     * 删除会话
     *
     * @param id id
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/16 17:27
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        chatService.remove(id);
        return success();
    }

    /**
     * 删除所有会话
     *
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/16 17:27
     */
    @DeleteMapping("/all")
    public AjaxResult removeAll() {
        chatService.removeAll();
        return success();
    }
}
